home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / docs-source / features / expressions.hsc < prev    next >
Encoding:
Text File  |  1997-10-19  |  5.5 KB  |  150 lines

  1. <WEBPAGE chapter="hsc - Features - " title="Expressions"
  2.     PREV="assign.html"
  3.     NEXT=":macro/macros.html">
  4.  
  5. <P>Additionally to simple strings, you can use expressions to set the
  6. value of an attribute. Inside an expressions, you can refer to other
  7. attributes to obtain their value, and you also can use several operators.
  8.  
  9. <H2>General Syntax</H2>
  10.  
  11. <UL>
  12. <LI>To assign an expression, you must start with a <bracket> after the
  13.     <equal-sign> of the assignment. The expression ends with a
  14.     <closing-bracket>.
  15. <LI>String constants must be enclosed inside any kind of quotes.
  16. <LI>To refer to the value of another attribute, use the name of it.
  17.     The source attribute must be defined, and value had to be set.
  18. </UL>
  19.  
  20. <STRONG>Example:</STRONG><BR>
  21. <$source PRE>
  22. <$define image:string="hugo.gif">
  23. <IMG SRC=(image) ALT="image">
  24. </$source>
  25.  
  26. <P>will be converted to</P>
  27.  
  28. <$source PRE><IMG SRC="hugo.gif" ALT="image"></$source>
  29.  
  30. <H2><A NAME="operators">Operators</A></H2>
  31.  
  32. <H3>Unary Operators</H3>
  33. <DL>
  34.     <DT><A NAME="not"><CODE>not</CODE></A> <I>expression</I>
  35.     <DD>Negotiate (boolean) expression
  36.     <DT><A NAME="set"><CODE>set</CODE></A> <I>attribute</I>
  37.     <DD>True, if attribute has been set (read: passed a value)
  38.         within macro call.
  39.     <DT><A NAME="defined"><CODE>defined</CODE></A> <I>attribute</I>
  40.     <DD>True, if attribute was defined with <TG>$macro</TG> or
  41.         <TG>$define</TG>
  42.     <DT><A NAME="exists"><CODE>Exists(</CODE></A><I>local uri</I><CODE>)</CODE>
  43.     <DD>True, if document at local URI exists (<CODE>bool</CODE>).
  44.         This can also be specified as a <fe_prjuri>.<BR>
  45.         <ExampleNote><CODE>Exists("index.html")</CODE>,
  46.                      <CODE>Exists(":image/next.gif")</CODE>
  47.     <DT><A NAME="fexists"><CODE>fExists(</CODE></A><I>filename</I><CODE>)</CODE>
  48.     <DD>True, if a file exists (<CODE>bool</CODE>). If you do not specify
  49.         a full filename (including a device name), it will be relative to
  50.         the source root directory.<BR>
  51.         <ExampleNote><CODE>fExists("sepp:hugo/resi.hsc")</CODE>,
  52.                      <CODE>fExists("///child.txt")</CODE>,
  53.                      <CODE>fExists("include/global.hsc")</CODE>
  54.     <DT><CODE><A NAME="getenv">GetEnv</A>(</CODE><I>environment-variable</I><CODE>)</CODE>
  55.     <DD>Get value of an environment variable.<BR>
  56.         <ExampleNote><CODE>GetEnv("Workbench")</CODE>
  57.     <DT><CODE><A NAME="getfilesize">GetFileSize</A>(</CODE><I>local uri</I><CODE>)</CODE>
  58.     <DD>Get size of a specific document.
  59.         You can use the attribute
  60.         <A HREF=":features/spcattr.html#format.filesize"><CODE>HSC.Format.FileSize</CODE></A>
  61.         to change the appearence of the result.<BR>
  62.         <ExampleNote><CODE>GetFileSize("../../download/hugo.lha")</CODE>,
  63.                      <CODE>GetFileSize(":nudes/resi.jpg")</CODE>
  64.     <DT><CODE><A NAME="getgmtime">GetGMTime()</A></CODE>
  65.     <DD>Get current Greenwich Mean time.
  66.         You can use the attribute
  67.         <A HREF=":features/spcattr.html#format.time"><CODE>HSC.Format.Time</CODE></A>
  68.         to change the appearence of the result.<BR>
  69.     <DT><CODE><A NAME="gettime">GetTime()</A></CODE>
  70.     <DD>Get current local time.
  71.         You can use the attribute
  72.         <A HREF=":features/spcattr.html#format.time"><CODE>HSC.Format.Time</CODE></A>
  73.         to change the appearence of the result.<BR>
  74. </DL>
  75.  
  76. <H3>Binary Operators</H3>
  77. <DL>
  78.     <DT><I>expression</I> <STRONG>=</STRONG> <I>expression</I>
  79.     <DD>string comparison (case insensitive)
  80.     <DT><I>expression</I> <STRONG>+</STRONG> <I>expression</I>
  81.     <DD>string concatenation
  82.     <DT><I>little</I> <STRONG>IN</STRONG> <I>big</I>
  83.     <DD>search for substring <I>littel</I> in <I>big</I> (case insensitive)
  84. </DL>
  85.  
  86. <STRONG>Example:</STRONG><BR>
  87. <$source PRE>
  88. <$define name:string="hugo">
  89. <$define here:string="here">
  90.  
  91. <IMG SRC=(name+".gif") ALT=(name+" was "+here)>
  92. <$if cond=(name="hugo")>
  93. This is hugo!
  94. <$else>
  95. Maybe it's sepp?
  96. </$if>
  97. <$if cond=("SePp" IN "hugo,sepp and resi")>
  98. Sepp is among them.
  99. </$if>
  100. AmigaOS version: <(GetEnv ("KickStart"))>
  101. </$source>
  102.  
  103. <P>will be converted to</P>
  104.  
  105. <PRE>
  106. <TG>IMG SRC="hugo.gif" ALT="hugo was here"</TG>
  107. This is hugo!
  108. Sepp is among them.
  109. AmigaOS version: <(GetEnv ("KickStart"))>
  110. </PRE>
  111.  
  112. <P>At least on my machine.</P>
  113.  
  114. <H2><A NAME="boolean">Boolean Expressions</A></H2>
  115.  
  116. <P>If you pass an expression to a boolean attribute, the expression is
  117. evaluated as before. If the expression returned an empty string,
  118. the boolean attribute is interpreted as <CODE>false</CODE>. This will
  119. cause the attribute to be removed from the tag/macro-call.</P>
  120.  
  121. <P>Any none-empty string will set the attribute to <CODE>true</CODE>,
  122. resulting in a value equal to the name of attribute. (In html, writing 
  123. <CODE>ISMAP</CODE> is short for <CODE>ISMAP="ISMAP"</CODE>.)</P>
  124.  
  125. <STRONG>Example:</STRONG>
  126.  
  127. <$source PRE><IMG SRC=(name) ALT="nufin" ISMAP=(name="map.gif")></$source>
  128.  
  129. <P>will be converted to</P>
  130.  
  131. <$source PRE><IMG SRC="hugo.gif" ALT="nufin"></$source>
  132.  
  133. <P>if <CODE>name</CODE> has been set to <CODE>"hugo.gif"</CODE>,
  134. or to</P>
  135.  
  136. <$source PRE><IMG SRC="map.gif" ALT="nufin" ISMAP></$source>
  137.  
  138. <P>if <CODE>name</CODE> has been set to <CODE>"map.gif"</CODE>. Note that
  139. only the second call enables the boolean attribute <CODE>ISMAP</CODE>,
  140. while it gets stripped for the first call.</P>
  141.  
  142. <H2><A NAME="priorities">Priorities</A></H2>
  143. <P><STRONG>Important:</STRONG> Different to most programming languages, <hsc>
  144. does not support priorities for different operators. Therefor, expressions
  145. are simply processed sequentially (Programmer's lazyness rules).</P>
  146.  
  147. <P>But you can use nested brackets within complex expressions.</P>
  148.  
  149. </WEBPAGE>
  150.